home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
CHARCNT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-23
|
2KB
|
92 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: charcnt.c
// Title: Data Compression Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This is a utility to count the frequency of characters directed to it
// through standard input.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <stdio.h>
#include <ctype.h>
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns:
//----------------------------------------------------------------------------
int main(void)
{
static long count[128];
long total = 0;
long max_count;
int i, max_char;
int ch;
while ((ch = getchar()) != EOF)
{
ch &= 0x7F;
ch = toupper(ch);
total++;
count[ch]++;
}
printf("%ld characters.\n", total);
do
{
max_count = 0;
for (i = 0; i < 128; ++i)
if (count[i] > max_count)
{
max_char = i;
max_count = count[i];
}
if (max_count)
{
ch = (int)(isprint(max_char) ? max_char: ' ');
printf(" '%c' (%3d) %ld\n", ch, ch, count[max_char]);
count[max_char] = 0;
}
}
while (max_count);
return 0;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------